package com.cykj.web.controller.posbiz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.core.page.TableDataInfo;
import com.cykj.common.enums.BusinessType;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.pos.domain.BizOrganization;
import com.cykj.pos.service.IBizOrganizationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 机构信息Controller
 * 
 * @author ruoyi
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/system/organization")
public class BizOrganizationController extends BaseController
{
    @Autowired
    private IBizOrganizationService bizOrganizationService;

    /**
     * 查询机构信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:organization:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizOrganization bizOrganization)
    {
        startPage();
        List<BizOrganization> list = bizOrganizationService.selectBizOrganizationList(bizOrganization);
        return getDataTable(list);
    }

    /**
     * 导出机构信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:organization:export')")
    @Log(title = "机构信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizOrganization bizOrganization)
    {
        List<BizOrganization> list = bizOrganizationService.selectBizOrganizationList(bizOrganization);
        ExcelUtil<BizOrganization> util = new ExcelUtil<BizOrganization>(BizOrganization.class);
        util.exportExcel();
    }

    /**
     * 获取机构信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:organization:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizOrganizationService.selectBizOrganizationById(id));
    }

    /**
     * 新增机构信息
     */
    @PreAuthorize("@ss.hasPermi('system:organization:add')")
    @Log(title = "机构信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizOrganization bizOrganization)
    {
        return toAjax(bizOrganizationService.insertBizOrganization(bizOrganization));
    }

    /**
     * 修改机构信息
     */
    @PreAuthorize("@ss.hasPermi('system:organization:edit')")
    @Log(title = "机构信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizOrganization bizOrganization)
    {
        return toAjax(bizOrganizationService.updateBizOrganization(bizOrganization));
    }

    /**
     * 删除机构信息
     */
    @PreAuthorize("@ss.hasPermi('system:organization:remove')")
    @Log(title = "机构信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizOrganizationService.deleteBizOrganizationByIds(ids));
    }
}
